/******************************************************************************
*                                                                             *
* UTICA softcore v0.1                                                         *
*                                                                             *
* Copyright (c) 2012 Andrew D. Zonenberg                                      *
* All rights reserved.                                                        *
*                                                                             *
* Redistribution and use in source and binary forms, with or without modifi-  *
* cation, are permitted provided that the following conditions are met:       *
*                                                                             *
*    * Redistributions of source code must retain the above copyright notice  *
*      this list of conditions and the following disclaimer.                  *
*                                                                             *
*    * Redistributions in binary form must reproduce the above copyright      *
*      notice, this list of conditions and the following disclaimer in the    *
*      documentation and/or other materials provided with the distribution.   *
*                                                                             *
*    * Neither the name of the author nor the names of any contributors may be*
*      used to endorse or promote products derived from this software without *
*      specific prior written permission.                                     *
*                                                                             *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN     *
* NO EVENT SHALL THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT,         *
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    *
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY       *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT         *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF    *
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           *
*                                                                             *
******************************************************************************/

/**
	@file MainWindow.h
	@author Andrew D. Zonenberg
	@brief Main application window
 */

#ifndef MainWindow_h
#define MainWindow_h
#include <gtkmm/actiongroup.h>
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/label.h>
#include <gtkmm/filechooserdialog.h>
#include <gtkmm/frame.h>
#include <gtkmm/liststore.h>
#include <gtkmm/listviewtext.h>
#include <gtkmm/main.h>
#include <gtkmm/paned.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/widget.h>
#include <gtkmm/window.h>

#include <vector>
#include <map>

#include "Graph.h"

class MainWindow : public Gtk::Window
{
public:
	MainWindow(std::string tty);
	~MainWindow();
	
	////////////////////////////////////////////////////////////////////////////////////////////////
	//UI stuff
	
	Gtk::VBox m_vbox;
		Gtk::Frame m_vframe;
			Gtk::HBox m_vhbox;
				Graph m_vgraph;
				Gtk::VBox m_vvbox;
					Gtk::Label m_v33label;
					Gtk::Label m_v25label;
					Gtk::Label m_v12label;
		Gtk::Frame m_iframe;
			Gtk::HBox m_ihbox;
				Graph m_igraph;
				Gtk::VBox m_ivbox;
					Gtk::Label m_i33label;
					Gtk::Label m_i25label;
					Gtk::Label m_i12label;
		Gtk::Frame m_pframe;
			Gtk::HBox m_phbox;
				Graph m_pgraph;
				Gtk::VBox m_pvbox;
					Gtk::Label m_p33label;
					Gtk::Label m_p25label;
					Gtk::Label m_p12label;
		Gtk::Frame m_tframe;
			Gtk::HBox m_thbox;
				Graph m_tgraph;
				Gtk::VBox m_tvbox;
					Gtk::Label m_tpsulabel;
					Gtk::Label m_tamblabel;
	
	Graphable m_3v3;
	Graphable m_2v5;
	Graphable m_1v2;
	
	Graphable m_tpsu;
	Graphable m_tamb;
	
	pthread_mutex_t m_mutex;
	
	std::string m_ttyfname;
	
	float v_33;
	float v_25;
	float v_12;
	
	float i_33;
	float i_25;
	float i_12;
	
	float p_33;
	float p_25;
	float p_12;
	
	float t_amb;
	float t_psu;
	
	int read_looped(int fd, unsigned char* buf, int count);
	
protected:

	//Initialization
	void CreateWidgets();
	
	bool OnTimer(int nTimer);

};

double GetTime();

#endif
